<?php
/**
 * @version		$Id: controller.php 16385 2010-04-23 10:44:15Z ian $
 * @package		Joomla
 * @subpackage	Content
 * @copyright	Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant to the
 * GNU General Public License, and as distributed it includes or is derivative
 * of works licensed under the GNU General Public License or other free or open
 * source software licenses. See COPYRIGHT.php for copyright notices and
 * details.
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );

jimport('joomla.application.component.controller');

/**
 * User Component Controller
 *
 * @package		Joomla
 * @subpackage	Weblinks
 * @since 1.5
 */
class UserController extends JController
{
	/**
	 * Method to display a view
	 *
	 * @access	public
	 * @since	1.5
	 */
	function display()
	{
		parent::display();
	}
    
    function success(){
		$userid = JRequest::getVar('userid');
		$user = JFactory::getUser($userid);
		/*if(JRequest::getVar('active') != 1){
			UserController::_sendMail($user);
		}*/
		UserController::_sendMailPayment($user);
        $this->setredirect('index.php?option=com_user&view=register&layout=success&Itemid=13');
    }
	
	function processReturn(){
        $db		=& JFactory::getDBO();
        $userid = JRequest::getVar('userid');
		$orderid = JRequest::getVar('orderid');
		
        $query = "UPDATE #__users SET checkout_status = 1 WHERE id = ".$userid;
        $db->setQuery($query);
        $db->query();
		
		$query = "UPDATE #__users_pay SET success = 1, transaction = '".JRequest::getVar('transaction')."' WHERE id = ".$orderid;
        $db->setQuery($query);
        $db->query();
    }
    
    function error(){
        $this->setredirect('index.php?option=com_user&view=register&layout=error&Itemid=13');
    }
    
	function edit()
	{
		global $mainframe, $option;

		$db		=& JFactory::getDBO();
		$user	=& JFactory::getUser();

		if ( $user->get('guest')) {
			JError::raiseError( 403, JText::_('Access Forbidden') );
			return;
		}

		JRequest::setVar('layout', 'form');
       // print_r($user);
		parent::display();
	}

	function save()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
        
		$user	 =& JFactory::getUser();
		$userid = JRequest::getVar( 'id', 0, 'post', 'int' );

		// preform security checks
		if ($user->get('id') == 0 || $userid == 0 || $userid <> $user->get('id')) {
			JError::raiseError( 403, JText::_('Access Forbidden') );
			return;
		}

		//clean request
		$post = JRequest::get( 'post' );
		$post['username']	= JRequest::getVar('username', '', 'post', 'username');
		$post['password']	= JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW);
		$post['password2']	= JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW);
	
		// get the redirect
		$return = JURI::base();
		
		// do a password safety check
		if(strlen($post['password']) || strlen($post['password2'])) { // so that "0" can be used as password e.g.
			if($post['password'] != $post['password2']) {
				$msg	= JText::_('PASSWORDS_DO_NOT_MATCH');
				// something is wrong. we are redirecting back to edit form.
				// TODO: HTTP_REFERER should be replaced with a base64 encoded form field in a later release
				$return = str_replace(array('"', '<', '>', "'"), '', @$_SERVER['HTTP_REFERER']);
				if (empty($return) || !JURI::isInternal($return)) {
					$return = JURI::base();
				}
				$this->setRedirect($return, $msg, 'error');
              //  print_r($user);die;
				return false;
			}
		}

		// we don't want users to edit certain fields so we will unset them
		unset($post['gid']);
		unset($post['block']);
		unset($post['usertype']);
		unset($post['registerDate']);
		unset($post['activation']);

		// store data
		$model = $this->getModel('user');

		if ($model->store($post)) {
			$msg	= JText::_( 'Your settings have been saved.' );
		} else {
			//$msg	= JText::_( 'Error saving your settings.' );
			$msg	= $model->getError();
		}

		
		$this->setRedirect( 'index.php?option=com_user&view=user&layout=profile&Itemid=13', $msg );
	}

	function cancel()
	{
		$this->setRedirect( 'index.php' );
	}

	function login()
	{ 
		// Check for request forgeries
        //print_r($_POST);die;
		JRequest::checkToken('request') or jexit( 'Invalid Token' );
		global $mainframe;
        
      //  print_r($return);
		if ($return = JRequest::getVar('return', '', 'method', 'base64')) {
			$return = base64_decode($return);
			if (!JURI::isInternal($return)) {
				$return = '';
			}
		}

		$options = array();
		$options['remember'] = JRequest::getBool('remember', false);
		$options['return'] = $return;

		$credentials = array();
		$credentials['username'] = JRequest::getVar('username', '', 'method', 'username');
		$credentials['password'] = JRequest::getString('passwd', '', 'post', JREQUEST_ALLOWRAW);

		if($options['remember']){
			setcookie("username", $credentials['username'], time()+360000000);
			setcookie("password", $credentials['password'], time()+360000000);
		}
		
		//preform the login action
       //print_r($user);die;
		$error = $mainframe->login($credentials, $options);
            //die('aaa');
            
        //var_dump($error);
        
        //  $this ->redirect('index.php?option=com_user&view=user&layout=profile&Itemid=13');
		if(!JError::isError($error))
		{ 
		  
            
			// Redirect if the return url is not registration or login
			if ( ! $return ) {
				$return	= 'index.php?option=com_user';
			}
            //modified - thai
          //  $return.= "?option=com_user&view=user&layout=profile&Itemid=13";
		  $db = JFactory::getDBO();
		  	if(date("N", time()) == 2){
				$user = JFactory::getUser();
				$user = JFactory::getUser($user->id);
				if($user->gid == 18 || $user->gid == 19){
					$date = date("d.m.Y", time());
					$time = date("H:i:s", time());
					$name = $user->name;
					$email = $user->email;
					$gid = $user->gid;
					$query = "INSERT INTO #__auction_visit(name, email, gid, log_time, log_date) VALUES ('".$name."', '".$email."', ".$gid.", '".$time."', '".$date."')";
					$db->setQuery($query);
					$db->query();
				}
			}
			$db->setQuery("SELECT auction_date FROM #__auction_date WHERE id = 2");
			$status = $db->loadResult();
			if($status){
				$mainframe->redirect( "index.php?option=com_auction&view=list&Itemid=10" );
			} else {
				$mainframe->redirect( "index.php?option=com_ecommerce&view=katalog&Itemid=8" );
			}
		}
		else
		{
			// Facilitate third party login forms
			if ( ! $return ) {
			 	 
				$return	= 'index.php?option=com_user&view=login&Itemid=13';
	
        	}

			// Redirect to a login form
           
			$mainframe->redirect( 'index.php?option=com_user&view=login&Itemid=13' );
		}
	}

	function logout()
	{
		global $mainframe;

		//preform the logout action
        
		$error = $mainframe->logout();

		if(!JError::isError($error))
		{
			if ($return = JRequest::getVar('return', '', 'method', 'base64')) {
				$return = base64_decode($return);
				if (!JURI::isInternal($return)) {
					$return = 'index.php?option=com_user&view=login';
				}
			}

			// Redirect if the return url is not registration or login
			if ( $return && !( strpos( $return, 'com_user' )) ) {
				$mainframe->redirect( 'index.php?option=com_user&view=login&Itemid=13' );
			}
            $mainframe->redirect( 'login-online-auktion.html' );
		} else {
			parent::display();
		}
	}

	/**
	 * Prepares the registration form
	 * @return void
	 */
	function register()
	{
		$usersConfig = &JComponentHelper::getParams( 'com_users' );
		if (!$usersConfig->get( 'allowUserRegistration' )) {
			JError::raiseError( 403, JText::_( 'Access Forbidden' ));
			return;
		}

		$user 	=& JFactory::getUser();

		if ( $user->get('guest')) {
			JRequest::setVar('view', 'register');
		} else {
			$this->setredirect('index.php?option=com_user&task=edit',JText::_('You are already registered.'));
		}

		parent::display();
	}

	/**
	 * Save user registration and notify users and admins if required
	 * @return void
	 */
	function register_save()
	{
		global $mainframe;
        
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );

		// Get required system objects
		$user 		= clone(JFactory::getUser());
		$pathway 	=& $mainframe->getPathway();
		$config		=& JFactory::getConfig();
		$authorize	=& JFactory::getACL();
		$document   =& JFactory::getDocument();

		// If user registration is not allowed, show 403 not authorized.
		$usersConfig = &JComponentHelper::getParams( 'com_users' );
		if ($usersConfig->get('allowUserRegistration') == '0') {
			JError::raiseError( 403, JText::_( 'Access Forbidden' ));
			return;
		}
           
		
        // Initialize new usertype setting
		$newUsertype = $usersConfig->get( 'new_usertype' );
		if (!$newUsertype) {
			
            $newUsertype = 'Registered';
		}
            
		// Bind the post array to the user object
		if (!$user->bind( JRequest::get('post'), 'usertype' )) {
			 
            JError::raiseError( 500, $user->getError());
		}
            
		// Set some initial user values
		$user->set('id', 0);
		$user->set('usertype', $newUsertype);
		$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));

		$date =& JFactory::getDate();
		$user->set('registerDate', $date->toMySQL());
        
		// If user activation is turned on, we need to set the activation information
		$useractivation = $usersConfig->get( 'useractivation' );
		if ($useractivation == '1')
		{
			jimport('joomla.user.helper');
			$user->set('activation', JUtility::getHash( JUserHelper::genRandomPassword()) );
			$user->set('block', '1');
		}

		// If there was an error with registration, set the message and display form
	//	print_r($user);die;
        //$user->set('password',"2");
        if ( !$user->save() )
		{
			JError::raiseWarning('', JText::_( $user->getError()));
			$this->register();
			return false;
		}
    //    print_r($user->password);die;
     //   print_r($user);die;
     
        $id=$user->id;
        $temp= sprintf("%04d", $id);
        $pro_number = "O" .$temp;
        $db	= &JFactory::getDBO();
        $query = "UPDATE #__users SET profile_number='".$pro_number."' WHERE id=". $id;
        $db->setQuery($query);
        $db->query();
        
		// Send registration confirmation mail
		$password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
		$password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email
     	//UserController::_sendMail($user, $password);
		UserController::_sendMail($user);

		// Everything went fine, set relevant message depending upon user activation state and display message
		if ( $useractivation == 1 ) {
			$message  = JText::_( 'REG_COMPLETE_ACTIVATE' );
		} else {
			$message = JText::_( 'REG_COMPLETE' );
		}
            
		$this->setRedirect('index.php?option=com_user&view=register&layout=payment&userid='.$user->id.'&Itemid=13');
  
	}

	function activate()
	{
		global $mainframe;

		// Initialize some variables
		$db			=& JFactory::getDBO();
		$user 		=& JFactory::getUser();
		$document   =& JFactory::getDocument();
		$pathway 	=& $mainframe->getPathWay();

		$usersConfig = &JComponentHelper::getParams( 'com_users' );
		$userActivation			= $usersConfig->get('useractivation');
		$allowUserRegistration	= $usersConfig->get('allowUserRegistration');

		// Check to see if they're logged in, because they don't need activating!
		if ($user->get('id')) {
			// They're already logged in, so redirect them to the home page
			$mainframe->redirect( 'index.php' );
		}

		if ($allowUserRegistration == '0' || $userActivation == '0') {
			JError::raiseError( 403, JText::_( 'Access Forbidden' ));
			return;
		}

		// create the view
		require_once (JPATH_COMPONENT.DS.'views'.DS.'register'.DS.'view.html.php');
		$view = new UserViewRegister();

		$message = new stdClass();

		// Do we even have an activation string?
		$activation = JRequest::getVar('activation', '', '', 'alnum' );
		$activation = $db->getEscaped( $activation );

		if (empty( $activation ))
		{
			// Page Title
			$document->setTitle( JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' ) );
			// Breadcrumb
			$pathway->addItem( JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' ));

			$message->title = JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' );
			$message->text = JText::_( 'REG_ACTIVATE_NOT_FOUND' );
			$view->assign('message', $message);
			$view->display('message');
			return;
		}

		// Lets activate this user
		jimport('joomla.user.helper');
		if (JUserHelper::activateUser($activation))
		{
			// Page Title
			$document->setTitle( JText::_( 'REG_ACTIVATE_COMPLETE_TITLE' ) );
			// Breadcrumb
			$pathway->addItem( JText::_( 'REG_ACTIVATE_COMPLETE_TITLE' ));

			$message->title = JText::_( 'REG_ACTIVATE_COMPLETE_TITLE' );
			$message->text = JText::_( 'REG_ACTIVATE_COMPLETE' );
			$this->setredirect('index.php?option=com_user&view=register&layout=active_success&Itemid=13');
		}
		else
		{
			// Page Title
			$document->setTitle( JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' ) );
			// Breadcrumb
			$pathway->addItem( JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' ));

			$message->title = JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' );
			$message->text = JText::_( 'REG_ACTIVATE_NOT_FOUND' );
		}

		$view->assign('message', $message);
		$view->display('message');
	}

	/**
	 * Password Reset Request Method
	 *
	 * @access	public
	 */
	function requestreset()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );

		// Get the input
		$email		= JRequest::getVar('email', null, 'post', 'string');

		// Get the model
		$model = &$this->getModel('Reset');

		// Request a reset
		if ($model->requestReset($email) === false)
		{
			$message = JText::sprintf('PASSWORD_RESET_REQUEST_FAILED', $model->getError());
     //       die('aaaa');
			$this->setRedirect('index.php?option=com_user&view=reset', $message);
			return false;
		}

		$this->setRedirect('index.php?option=com_user&view=reset&layout=confirm');
	}

	/**
	 * Password Reset Confirmation Method
	 *
	 * @access	public
	 */
	function confirmreset()
	{ 
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );

		// Get the input
		$token = JRequest::getVar('token', null, 'post', 'alnum');
		$username = JRequest::getVar('username', null, 'post');

		// Get the model
		$model = &$this->getModel('Reset');

		// Verify the token
		if ($model->confirmReset($token, $username) !== true)
		{
			$message = JText::sprintf('PASSWORD_RESET_CONFIRMATION_FAILED', $model->getError());
			$this->setRedirect('index.php?option=com_user&view=reset&layout=confirm', $message);
			return false;
		}
		$this->setRedirect('index.php?option=com_user&view=reset&layout=complete');
	}

	/**
	 * Password Reset Completion Method
	 *
	 * @access	public
	 */
	function completereset()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );

		// Get the input
		$password1 = JRequest::getVar('password1', null, 'post', 'string', JREQUEST_ALLOWRAW);
		$password2 = JRequest::getVar('password2', null, 'post', 'string', JREQUEST_ALLOWRAW);

		// Get the model
		$model = &$this->getModel('Reset');

		// Reset the password
		if ($model->completeReset($password1, $password2) === false)
		{
			$message = JText::sprintf('PASSWORD_RESET_FAILED', $model->getError());
			$this->setRedirect('index.php?option=com_user&view=reset&layout=complete', $message);
			return false;
		}

		$message = JText::_('PASSWORD_RESET_SUCCESS');
		$this->setRedirect('index.php?option=com_user&view=login', $message);
	}

	/**
	 * Username Reminder Method
	 *
	 * @access	public
	 */
	function remindusername()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );

		// Get the input
		$email = JRequest::getVar('email', null, 'post', 'string');

		// Get the model
		$model = &$this->getModel('Remind');

		// Send the reminder
		if ($model->remindUsername($email) === false)
		{
			$message = JText::sprintf('USERNAME_REMINDER_FAILED', $model->getError());
			$this->setRedirect('index.php?option=com_user&view=remind', $message);
			return false;
		}

		$message = JText::sprintf('USERNAME_REMINDER_SUCCESS', $email);
		$this->setRedirect('index.php?option=com_user&view=login', $message);
	}

	function _sendMail(&$user)
	{
		global $mainframe;

		$db		=& JFactory::getDBO();
        
		$name 		= $user->get('name');
		$email 		= $user->get('email');
		$username 	= $user->get('username');

		$usersConfig 	= &JComponentHelper::getParams( 'com_users' );
		$sitename 		= $mainframe->getCfg( 'sitename' );
		$useractivation = $usersConfig->get( 'useractivation' );
		$mailfrom 		= $mainframe->getCfg( 'mailfrom' );
		$fromname 		= $mainframe->getCfg( 'fromname' );
		$siteURL		= JURI::base();

		$subject 	= sprintf ( JText::_( 'Account details for' ), $name, $sitename);
		$subject 	= html_entity_decode($subject, ENT_QUOTES);

		if ( $useractivation == 1 ){
			$message = sprintf ( JText::_( 'SEND_MSG_ACTIVATE' ), $name, $sitename, $siteURL."index.php?option=com_user&task=activate&activation=".$user->get('activation'), $siteURL, $username);
		} else {
			$message = sprintf ( JText::_( 'SEND_MSG' ), $name, $sitename, $siteURL);
		}

		$message = html_entity_decode($message, ENT_QUOTES);

		//get all super administrator
		$query = 'SELECT name, email, sendEmail' .
				' FROM #__users' .
				' WHERE LOWER( usertype ) = "super administrator"';
		$db->setQuery( $query );
		$rows = $db->loadObjectList();

		// Send email to user
		if ( ! $mailfrom  || ! $fromname ) {
			$fromname = $rows[0]->name;
			$mailfrom = $rows[0]->email;
		}

		JUtility::sendMail($mailfrom, $fromname, $email, $subject, $message);

		// Send notification to all administrators
		$subject2 = sprintf ( JText::_( 'Account details for' ), $name, $sitename);
		$subject2 = html_entity_decode($subject2, ENT_QUOTES);

		// get superadministrators id
		foreach ( $rows as $row )
		{
			if ($row->sendEmail)
			{
				$message2 = sprintf ( JText::_( 'SEND_MSG_ADMIN' ), $row->name, $sitename, $name, $email, $username);
				$message2 = html_entity_decode($message2, ENT_QUOTES);
				JUtility::sendMail($mailfrom, $fromname, $row->email, $subject2, $message2);
			}
		}
        
	}
	
	function _sendMailPayment(&$user)
	{
		global $mainframe;

		$db		=& JFactory::getDBO();
        
		$name 		= $user->get('name');
		$email 		= $user->get('email');

		$usersConfig 	= &JComponentHelper::getParams( 'com_users' );
		$sitename 		= $mainframe->getCfg( 'sitename' );
		$useractivation = $usersConfig->get( 'useractivation' );
		$mailfrom 		= $mainframe->getCfg( 'mailfrom' );
		$fromname 		= $mainframe->getCfg( 'fromname' );
		$siteURL		= JURI::base();
		
		$query = 'SELECT up.date, up.id as order_id, u.* FROM #__users_pay up INNER JOIN #__users as u ON up.user_id = u.id WHERE u.id = '.$user->id;
		$db->setQuery($query);
		$user_info = $db->loadObject(); 
		$tmp = explode(' ', $user_info->date);
		$tmp1 = explode('-', $tmp[0]);
		$date = $tmp1[2].'-'.$tmp1[1].'-'.$tmp1[0];
		$subject 	= $sitename.' - Ordrebekræftelse '.$user_info->order_id;
		$message = '<body style="font-family: \'Lucida Sans Unicode\', \'Lucida Grande\', sans-serif; ">

<table style="width:780px; margin:0px auto; padding:10px;" width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
  	<td colspan="1">
    	<table width="780px" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td style="background-color:#999999; padding:1px; color:white; font-size:15px; font-weight:bold;" colspan="2" >Ordreinformation</td>
          </tr>
          <tr>
            <td style="color:#323232; font-size:12px; padding:1px;" width="313">Ordre nummer:</td>
            <td width="467" style="color:#323232; font-size:12px; padding:1px;">'.$user_info->order_id.'</td>
          </tr>
		  <tr>
            <td style="color:#323232; font-size:12px; padding:1px;" width="313">Faktura dato:</td>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">'.$date.'</td>
          </tr>
          <tr>
            <td style="background-color:#999999; padding:1px; color:white; font-size:15px; font-weight:bold;" colspan="2" >Kundeinformation</td>
          </tr>
          
          <tr>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">Kundenavn:</td>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">'.$user_info->name.'</td>
          </tr>
          <tr>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">Adresse:</td>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">'.$user_info->address.'</td>
          </tr>
          <tr>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">Postnummer:</td>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">'.$user_info->post.'</td>
          </tr>
          <tr>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">By:</td>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">'.$user_info->city.'</td>
          </tr>
          <tr>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">Telefon/mobil:</td>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">'.$user_info->phone.'</td>
          </tr>
		  <tr>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">Firma-navn:</td>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">'.$user_info->company.'</td>
          </tr>
          <tr>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">CVR-nr.:</td>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">'.$user_info->cvr.'</td>
          </tr>
          <tr>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">E-mail:</td>
            <td style="color:#323232; font-size:12px; padding:1px; width:30%; ">'.$user_info->email.'</td>
          </tr>
       </table>
    </td>
  </tr>
  <tr>
  	<td style="border-bottom: 1px solid #999999;">
  		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
	            <td style="background-color:#999999; padding:1px; color:white; font-size:15px; font-weight:bold;" colspan="8" >Ordrelinier</td>
	        </tr>
			<tr>
		       	<td width="85" style="color:#323232; font-size:11px; text-align:center; padding:1px; ">Antal</td>
		       	<td width="241" style="color:#323232; font-size:11px; text-align:center; padding:1px; ">Navn</td>
		       	<td width="125" style="color:#323232; font-size:11px; text-align:center; padding:1px; ">Pris/enhed</td>
                <td width="212" style="color:#323232; font-size:11px; text-align:center; padding:1px; ">Subtotal</td>
                		    
		    </tr>
			
			<tr>
		       	<td style="color:#323232; font-size:11px; text-align:center; padding:1px; ">1</td>
		       	<td style="color:#323232; font-size:11px; text-align:center; padding:1px; ">Login online auktion</td>
		       	<td style="color:#323232; font-size:11px; text-align:center; padding:1px; ">DKK 3.000,-</td>
				<td style="color:#323232; font-size:11px; text-align:center; padding:1px; ">DKK 3.000,-</td>
		    </tr>    
        </table>
  	</td>
  </tr>
  <tr>
  	
  	<td style="text-align: right; color:#323232; font-size:14px; padding:0px; padding:2px 43px 50px 0; font-weight: bold;">Total at betale: DKK 3.000,-</td>
  </tr>
  <tr>
  	<td style="background-color:#999999; padding:1px; ">
  		<p style="color:#FFF; font-size:13px; margin:0;"> Dansk Automobil Børs · Sandbækvej 3 · 2610 Rødovre · Tlf. +45 33 21 37 33 · Fax. +45 33 21 37 44 · Email: info@dabauk.dk</p> 
	</td>
  </tr>
</table>
</body>';

		//get all super administrator
		$query = 'SELECT name, email, sendEmail' .
				' FROM #__users' .
				' WHERE LOWER( usertype ) = "super administrator"';
		$db->setQuery( $query );
		$rows = $db->loadObjectList();

		// Send email to user
		if ( ! $mailfrom  || ! $fromname ) {
			$fromname = $rows[0]->name;
			$mailfrom = $rows[0]->email;
		}

		JUtility::sendMail($mailfrom, $fromname, $email, $subject, $message, true);
	}
}
?>
